package com.example.myapplication8;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class showques extends AppCompatActivity{

    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_showques);
        ListView lstv=findViewById(R.id.show);
        SimpleAdapter adapter=new SimpleAdapter(showques.this,mylst(),R.layout.lstitem,new String[]{"id","contain","a","b","c","d"},new int[]{R.id.num,R.id.contain,R.id.choA,R.id.choB,R.id.choC,R.id.choD});
        lstv.setAdapter(adapter);
    }
    public ArrayList<Map<String,Object>> mylst()
    {
        try {
            String filename="question.txt";
            FileInputStream fis=openFileInput(filename);
            byte[] ready=new byte[fis.available()];
            while(fis.read(ready)!=-1){
            }
            //text是所有的文字
            String text=new String(ready);
            fis.close();
            //ques是每一小项
            String[] ques=text.split(" ");
            ArrayList<Map<String,Object>> lst=new ArrayList<Map<String,Object>>();
            HashMap<String,Object> item1=new HashMap<String,Object>();
            HashMap<String,Object> item2=new HashMap<String,Object>();
            HashMap<String,Object> item3=new HashMap<String,Object>();
            String[] key=new String[]{"id","contain","a","b","c","d"};
            for(int i=0;i<6;i++)
            {
                item1.put(key[i],ques[i]);
                item2.put(key[i],ques[i+6]);
                item3.put(key[i],ques[i+12]);
            }
            lst.add(item1);
            lst.add(item2);
            lst.add(item3);
            return lst;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    public void enterxml(View view) {
        Intent intent=new Intent(this,showxml.class);
        startActivity(intent);
    }
}